package com.bangcommunity.bbframe.fdfs;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;

public class FdfsSourceInputStream extends InputStream {

    private static Logger logger = LoggerFactory.getLogger(FdfsSourceInputStream.class);
    private InputStream inputStream;
    private long size = -1;
    private long index = 0;
    @Override
    public int read() throws IOException {
        if(index++ >= size){
            return -1;
        }
        int read = inputStream.read();
        if(read == -1){
            return -1;
        }
        return read;

    }

    @Override
    public int read(byte[] b) throws IOException {
        return super.read(b);
    }

    @Override
    public int read(byte[] b, int off, int len) throws IOException {
        return super.read(b, off, len);
    }

    @Override
    public long skip(long n) throws IOException {
        return super.skip(n);
    }

    @Override
    public int available() throws IOException {
        return inputStream.available();
    }

    @Override
    public void close() throws IOException {
//        inputStream.close();
    }

    @Override
    public synchronized void mark(int readlimit) {
        inputStream.mark(readlimit);
    }

    @Override
    public synchronized void reset() throws IOException {
        inputStream.reset();
        index =  0;
    }
    public FdfsSourceInputStream(InputStream inputStream,long size) {
        super();
        this.inputStream = inputStream;
        this.size = size;
    }

    public long getSize() {
        return size;
    }

    public void setSize(long size) {
        this.size = size;
    }

    public InputStream getInputStream() {
        return inputStream;
    }

    public void setInputStream(InputStream inputStream) {
        this.inputStream = inputStream;
    }
}
